package com.android.filesystem;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

public class FileSystemDemoActivity extends Activity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		TextView text = (TextView) this.findViewById(R.id.text);
		File folder = new File("/sdcard", "folder");
		boolean check = folder.mkdirs();
		Log.i("Check", "check is : " + check);
		File myfile = new File("/sdcard/folder", "myfile.txt");
		try {
			myfile.createNewFile();
		} catch (IOException e) {
			Log.i("File Error", "File can't create");
		}
		try {
			OutputStream outfile = new FileOutputStream(myfile);

			outfile.write(new String("Dao Huu Bien").getBytes());

			outfile.flush();
			outfile.close();
		} catch (IOException ioex) {
			Log.i("Activity", "File output stream error");
			if (text != null)
				text.setText(ioex.getMessage());
			else
				Log.i("Error", "text is null");
		}
		setparameter(123);
	}

	public void setparameter(int ilevel) {
		byte[] buffer = new byte[8];
		buffer[0] = (byte) ilevel;
		OutputStream output = null;
		try {
			output = openFileOutput("option.txt", MODE_WORLD_READABLE);
			output.write(buffer);
			output.flush();
			output.close();
		} catch (IOException e) {
		}
	}
}